package com.intelli4.pos.controllers.impl;

import java.util.ArrayList;
import java.util.List;

import com.intelli4.pos.controllers.GenericEventManager;
import com.intelli4.pos.events.GenericEvent;
import com.intelli4.pos.listeners.GenericListener;

public class GenericEventManagerImpl<E extends GenericEvent, L extends GenericListener<E>>
		implements GenericEventManager<E, L> {
	private List<L> listeners = new ArrayList<L>();

	@Override
	public void addListener(L listener) {
		listeners.add(listener);
	}

	@Override
	public void removeListener(L listener) {
		listeners.remove(listener);
	}

	@Override
	public boolean fireEvent(E event) {
		for (L listener : listeners) {
			if (!listener.onEvent(event))
				return false;
		}

		return true;
	}
}
